// pages/shop/orderby.js
var app = getApp();
var currentCateId = 0;
Page({
  data: {
  
  },
  onLoad: function (options) {

    currentCateId = parseInt(options.id);
  },
  onReady: function () {
    if (currentCateId > 0) {
      var that = this;
      app.func.req('product_cates/show', {
        id: currentCateId
      }, 'GET', function (res) {
        if (res.code == 'success') {
          that.setData({
            category: res.result
          })
        }
      }, {
          'token': wx.getStorageSync('token')
        });
    }
  },
  save: function (e) {
    var that = this;
    app.func.req('product_cates/update', {
      id: that.data.category.id,
      orderby: e.detail.value.orderby
    }, 'POST', function (res) {
      if (res.code == 'success') {
        wx.showToast({
          title: '调整顺序成功！',
          icon: 'success',
          duration: 2000,
          mask: true,
          success: function () {
            wx.switchTab({
              url: './products'
            })
          }
        });
      } else {
        wx.showToast({
          title: '调整顺序失败',
          icon: 'error',
          duration: 2000,
          mask: true
        });
      }
    }, {
        'token': wx.getStorageSync('token')
      });
  }
})